{{extends file="backend/layout.tpl"}} 

{{block name=title}}注册{{/block}}

{{block name=header}}
<style>
  body,
  html {
    height: 100%;
    background-color: gray;
  }
  .title {
    margin-bottom: 20px;
    text-align: center;
  }
  .main {
    width: 400px;
    margin: 100px auto;
    background-color: #fff;
    padding: 10px;
    border-radius: 10px;
  }
  .lk {
    text-align: center;
  }
</style>
{{/block}} {{block name=content}}
<body>
   <div class="main">
      <h1 class="title">注册</h1>
      <form class="layui-form" lay-filter="formDemo" action="">
        {{csrf_token}}
        <div class="layui-form-item">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-block">
            <input
              type="text"
              name="username"
              required
              lay-verify="required"
              placeholder="请输入用户名"
              autocomplete="off"
              class="layui-input"
            />
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">密码</label>
          <div class="layui-input-block">
            <input
              type="password"
              name="password"
              required
              lay-verify="required"
              placeholder="请输入密码"
              autocomplete="off"
              class="layui-input"
            />
          </div>
        </div>

          <div class="layui-form-item">
          <label class="layui-form-label">确认密码</label>
          <div class="layui-input-block">
            <input
              type="password"
              name="repassword"
              required
              lay-verify="required"
              placeholder="请输入密码"
              autocomplete="off"
              class="layui-input"
            />
          </div>
        </div>

        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">
              注册
            </button>
            <button type="reset" class="layui-btn layui-btn-primary">
              重置
            </button>
          </div>
        </div>
      </form>

      <div class="lk">
        <a href="/admin/login">已有账户？返回登录</a>
      </div>
    </div>

  {{/block}} {{block name=script}}
  <script>
    //Demo
    layui.use("form", function () {
      var form = layui.form;
      var $ = layui.jquery;

      //监听提交
      form.on("submit(formDemo)", function (dat) {
        // layer.msg(JSON.stringify(data.field));
        $.ajax({
          type: "POST",
          url: "register",
          data: dat.field,
          dataType: "json",
          success: function (response) {
            console.log(response);
            if (response.code == 1) {
              layer.msg(response.msg, { icon: 6 });
            }else{
              layer.msg(response.msg, { icon: 5 });
            }
          }
        });
        return false;
      });
    });
  </script>
{{/block}}

